/**
 * @alias 背景处理
 */
export function bgStyle(urlimg, params) {
	let style = {};
	if (urlimg) {
		style = {
			'backgroundImage': `url("${formatImg(urlimg,params)}")`,
			'backgroundSize': '100% 100%'
		}
	} else {
		style = null;
	}
	return style;
};
/**
 * @alias 跳转方法
 */
export function jumpPage(url, type = 'navigateTo') {
	uni[type]({
		url
	})
}
/**
 * @alias toast提示
 */
export function toast(message, success = () => true) {
	if (typeof message === 'string') {
		uni.showToast({
			title: message,
			icon: "none",
			success,
		})
	} else {
		uni.showToast(message);
	}
}
/**
 * @alias 清除所有提示
 */
export function clearToast(message) {
	uni.hideToast()
	uni.hideLoading()
}
/**
 * @alias 格式化时间
 * @param { string } sec = 当前时间 - 时间戳, 单位s
 * @param { number } type = 0 - 格式化类型, 0 显示全年月日, 用.分隔, 1 显示全年月日, 用 - 分隔, 2 显示 昨天今天, 用.分隔
 * @param { number } showTime = 0 - 是否显示时分, 1 显示， 0 不显示
 * @param { number } showSecond = 0 - 是否显示秒, 1 显示， 0 不显示
 */
export function formatDate(sec = (+new Date() + '').slice(0, -3), type = 1, showTime = 1, showSecond = 0) {
	let date = new Date(+(sec + '000'));
	let year = date.getFullYear();
	let month = date.getMonth() + 1;
	let day = date.getDate();
	let hour = date.getHours();
	let min = date.getMinutes();
	let second = date.getSeconds();
	let today = new Date();
	let yesterday = new Date(+new Date() - 86400000);
	let dateStr = '';
	let separator = '.';
	if (type == 1) {
		separator = '-';
	}
	if (date.toDateString() == today.toDateString() && type == 2) {
		dateStr += '今天'
	} else if (date.toDateString() == yesterday.toDateString() && type == 2) {
		dateStr += '昨天'
	} else {
		if (month <= 9) {
			month = '0' + month;
		}
		if (day <= 9) {
			day = '0' + day;
		}
		if (type == 2) {
			if (year != today.getFullYear()) {
				dateStr += year + separator;
			}
		} else {
			dateStr += year + separator;
		}
		dateStr += month + separator + day + ' '
	}
	if (showTime) {
		if (hour <= 9) {
			hour = '0' + hour;
		}
		if (min <= 9) {
			min = '0' + min;
		}
		if (second <= 9) {
			second = '0' + second;
		}
		dateStr += hour + ':' + min;
		if (showSecond) {
			dateStr += ':' + second;
		}
	}
	return dateStr;
}



export function secondsToHMS(seconds) {
	// 计算小时、分钟和秒
	const hours = Math.floor(seconds / 3600);
	const minutes = Math.floor((seconds % 3600) / 60);
	const remainingSeconds = seconds % 60;

	// 将时间数据转换为 HH:MM:SS 格式
	const formattedTime =
		`${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`;

	return formattedTime;
}

/**
 * @alias 设置区间随机数
 */
export function getRandomInt(min, max) {
	min = Math.ceil(min); // 向上取整
	max = Math.floor(max); // 向下取整
	return Math.floor(Math.random() * (max - min + 1)) + min;
}

/**
 * @alias 格式化设置日程插件数据
 */
export function formatScheduleJson(data, eventId) {
	console.log(new Date(data.endTime).getTime())
	let schedule_json = {
		title: data.name,
		desc: data.planDetail,
		location: "",
		start: new Date(data.startTime).getTime(), //开始时间 毫秒
		end: new Date(data.endTime).getTime(), //结束时间 毫秒
		advanceTime: data.remindBeforeSecond, // 提前提醒时间
		rule: null, //重复规则
		eventId //日程ID
	}
	return schedule_json
}